#ifndef _PARAMETER_PEU_H
#define _PARAMETER_PEU_H

#include <lib/cassert.h>
#include "parameter.h"

typedef struct pcu_ctr{
	uint32_t base_config[3];
	uint32_t equalization[3];
	uint8_t rev[80];
}__attribute__((aligned(sizeof(unsigned long)))) peu_ctr_t;

typedef struct pcu_config {
	uint32_t magic;
	uint32_t version;
	uint32_t size;
	uint8_t rev1[4];
	uint32_t independent_tree;
	uint32_t base_cfg;
	uint8_t rev2[16];
	peu_ctr_t ctr_cfg[2];
}__attribute__((aligned(sizeof(unsigned long)))) peu_config_t;

/*
*	结构体变量偏移与参数配置说明中必须相同
*/
#define PEU_MAGIC_OFFSET					0x0
#define PEU_INDEPENDENT_TREE_OFFSET			0x10
#define PEU_BASE_CFG_OFFSET					0x14
#define PEU_0_CONTROLLER_OFFSET				0x28
#define PEU_1_CONTROLLER_OFFSET				0x90

#define PEU_C0_CFG_OFFSET					0x0
#define PEU_C1_CFG_OFFSET					0x4
#define PEU_C2_CFG_OFFSET					0x8
#define PEU_C0_EQ_OFFSET					0xC
#define PEU_C1_EQ_OFFSET					0x10
#define PEU_C2_EQ_OFFSET					0x14

#define PEU_CASSERT( offset, _member)						\
	 CASSERT(offset ==										\
		 __builtin_offsetof(peu_config_t, _member),			\
		 assert_##offset##_mismatch)

#define PEU_C_CASSERT( offset, _member)						\
	  CASSERT(offset == 									 \
		  __builtin_offsetof(peu_ctr_t, _member),		 \
		  assert_##offset##_mismatch)

 PEU_CASSERT(PEU_MAGIC_OFFSET, magic);
 PEU_CASSERT(PEU_INDEPENDENT_TREE_OFFSET, independent_tree);
 PEU_CASSERT(PEU_BASE_CFG_OFFSET, base_cfg);
 PEU_CASSERT(PEU_0_CONTROLLER_OFFSET, ctr_cfg[0]);
 PEU_CASSERT(PEU_1_CONTROLLER_OFFSET, ctr_cfg[1]);

 PEU_C_CASSERT(PEU_C0_CFG_OFFSET, base_config[0]);
 PEU_C_CASSERT(PEU_C1_CFG_OFFSET, base_config[1]);
 PEU_C_CASSERT(PEU_C2_CFG_OFFSET, base_config[2]);
 PEU_C_CASSERT(PEU_C0_EQ_OFFSET, equalization[0]);
 PEU_C_CASSERT(PEU_C1_EQ_OFFSET, equalization[1]);
 PEU_C_CASSERT(PEU_C2_EQ_OFFSET, equalization[2]);

/*************************************************/

#define PEU1_OFFSET	16

#define PEU_C_OFFSET_MODE	16
#define PEU_C_OFFSET_SPEED	0

#define GEN3	3
#define GEN2	2
#define GEN1	1
#define GENa	0

#define PEU0    0x0
#define PEU1    0x1

#define PEU_CTR_0	0x0
#define PEU_CTR_1	0x1
#define PEU_CTR_2	0x2

#ifdef CONFIG_PCI_PEU0_T
	#define CONFIG_PCI_PEU0 0x1
#else
	#define CONFIG_PCI_PEU0 0x0
#endif

#ifdef CONFIG_PCI_PEU1_T
	#define CONFIG_PCI_PEU1 0x1
#else
	#define CONFIG_PCI_PEU1 0x0
#endif

#endif
